<?php 
	get_header();
	get_template_part( 'slider2' );; 
?>
	<div id="content">
		<div class="template clear-fix" id="casestudy">
		<div class="tpl-left">
				<div class="heading-1 clear-fix">
					<h2>Galleri</h2>
				</div>
				<div id="service-list">
					<ul id="lstSupport">
						<?php 
							global $post;
							global $wpdb;
							global $wp_query;
							$paged = $wp_query->query_vars["paged"];
							$permalink = get_permalink();
							$gllr_options = get_option( 'gllr_options' );
							if( substr( $permalink, strlen( $permalink ) -1 ) != "/" )
							{
								if( strpos( $permalink, "?" ) !== false ) {
									$permalink = substr( $permalink, 0, strpos( $permalink, "?" ) -1 )."/";
								}
								else {
									$permalink .= "/";
								}
							}
							$count = 0;
							$args = array(
								'post_type'					=> 'gallery',
								'post_status'				=> 'publish',
								'orderby'						=> 'post_date',
								'posts_per_page'		=> -1
							);
							$second_query = new WP_Query( $args );
							$count_all_albums = count($second_query->posts);
							$per_page = 5;
							if( $paged != 0 )
								$start = $per_page * ($paged - 1);
							else
								$start = $per_page * $paged;
							if ($second_query->have_posts()) : while ($second_query->have_posts()) : $second_query->the_post();
								if( $count < $start ) {
									$count++;
									continue;
								}
								if( ( $count - $start ) > $per_page - 1 )
									break;
		
							$attachments = get_children( 'post_parent='.$post->ID.'&post_type=attachment&post_mime_type=image&numberposts=1' );
							$id = key($attachments);
							$image_attributes = wp_get_attachment_image_src( $id, 'album-thumb' );
							$count++;	

							//-- NTHN add: to mark menu choose
							$mark = 0;
							$strGalleyPost = '?gallery='.get_query_var('gallery'); 
							$strGalleryInCode = basename( get_permalink( $post->ID ) );
							if ( strcmp($strGalleyPost,$strGalleryInCode) == 0 ){
								$mark = 1;
							}						
						?>
						<li <?php echo ($mark==1)?'class="current-service"':'';?>>							
							<a href="<?php echo $permalink; echo basename( get_permalink( $post->ID ) ); ?>">
								<?php echo $post->post_title; ?>
							</a>							
						</li>						
						<?php endwhile; endif; wp_reset_query(); ?>						
					</ul>
				</div>
			</div>
			<div class="tpl-right">				
					<?php 
					global $post;
					$args = array(
						'post_type'					=> 'gallery',
						'post_status'				=> 'publish',
						'name'						=> substr(basename( $_SERVER['REQUEST_URI'] ), strpos( basename( $_SERVER['REQUEST_URI'] ), "=")),
						'posts_per_page'			=> 1
					);	
					$second_query = new WP_Query( $args ); 
					$gllr_options = get_option( 'gllr_options' );
					if ($second_query->have_posts()) : while ($second_query->have_posts()) : $second_query->the_post(); ?>
						<div class="heading clear-fix">
							<h2><?php the_title(); ?></h2>
						</div>						
						<div class="gallery-wrapper">
							<?php the_content(); 
							$posts = get_posts(array(
								"showposts"			=> -1,
								"what_to_show"		=> "posts",
								"post_status"		=> "inherit",
								"post_type"			=> "attachment",
								"orderby"			=> "post_date",
								"order"				=> "ASC",
								"post_mime_type"	=> "image/jpeg,image/gif,image/jpg,image/png",
								"post_parent"		=> $post->ID
							));
							
							if( count( $posts ) > 0 ) {														
							?>
								<ul id="gallery-list">
									<?php foreach( $posts as $attachment ) {										
										$key = "gllr_image_text";
										$image_attributes = wp_get_attachment_image_src( $attachment->ID, 'photo-thumb' );
										$image_attributes_large = wp_get_attachment_image_src( $attachment->ID, 'large' );
									?>
										
										<li>
																																	
											<a href="<?php echo $image_attributes_large[0]; ?>" class="mainImage">
												<img alt="" title="" src="<?php echo $image_attributes[0]; ?>" />
											</a>
											<a href="<?php echo $image_attributes_large[0]; ?>" class="zoomIcon" rel="prettyPhoto[demo]">
												<img src="<?php echo get_template_directory_uri(); ?>/images/hoverImage.png" alt="" />
											</a>
										</li>
										
										<?php 
									} 
										?>
										</ul>									
									</div>
								<?php }else{ ?>
								<div class="gallery_box_single">
									<p class="not_found"><?php _e('Beklager - intet at finde.', 'gallery'); ?></p>
								</div>
								<?php } ?>	
							</div>
							<div class="clear"></div>
						<?php endwhile; else: ?>
						<div class="gallery_box_single">
							<p class="not_found"><?php _e('Beklager - intet at finde.', 'gallery'); ?></p>
						</div>
						<?php endif; ?>				
				</div>
			</div>		
			
			</div>
		</div>	
<script>
	jQuery(document).ready(function(){
	 jQuery(".menu-item-157").addClass('menu-item menu-item-type-post_type menu-item-object-page current-menu-item page_item page-item-157 current_page_item menu-item-157 current-service');
	 });
</script>	
<?php get_footer(); ?>